//
//  YYNormalPushTransitionAnimation.m
//  NavigationAnimate
//
//  Created by YK on 16/3/30.
//  Copyright © 2016年 LovePlus. All rights reserved.
//

#import "YYNormalPushTransitionAnimation.h"

@implementation YYNormalPushTransitionAnimation

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
    return 0.5;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    
    
    //转场容器
    UIView *containerView = [transitionContext containerView];
    
    //转场前的视图
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    //转场后的视图
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    
    [containerView insertSubview:toVC.view aboveSubview:fromVC.view];
    
    toVC.view.frame = CGRectMake(width, 0, width, height);
    
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        fromVC.view.frame = CGRectMake(-width, 0, width, height);
        toVC.view.frame = CGRectMake(0, 0, width, height);
    } completion:^(BOOL finished) {
        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
    }];
}

@end
